/**
 * Copyright 2011 Clemens Lombriser <clemens@lom.ch>
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 * 
 */

package ch.lom.clemens.android.bibliography;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.view.View.OnClickListener;

public class MendeleyAuthActivity extends Activity {

	public static String PARAM_AUTHENTICATION_URL = "authentication_url";
	public static String RET_VERIFICATION_STRING = "verification_string";

    // The on-click listener for all devices in the ListViews
    private OnClickListener m_btnClick = new OnClickListener() {

		public void onClick(View v) {
    		String strCode = m_edtText.getText().toString();
    		
            // Create the result Intent and include the MAC address
            Intent intent = new Intent();
            intent.putExtra(RET_VERIFICATION_STRING, strCode);

            // Set result and finish this Activity
            setResult(Activity.RESULT_OK, intent);
            finish();
        }

    };


    // UI components
	private TextView m_lblText;
	private Button   m_btnTest;
	private EditText m_edtText;
	
	
	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mendeley_authentication);
        
        
        setTitle("Mendeley Authentication");

        m_lblText = (TextView)findViewById(R.id.auth_text);
        String strAuthURL = (String) getIntent().getExtras().get(PARAM_AUTHENTICATION_URL);
        m_lblText.setText("Please visit the following URL to obtain the verification code: \n" + strAuthURL);
        
        m_btnTest = (Button)findViewById(R.id.auth_button);
        m_btnTest.setOnClickListener(m_btnClick); 

        m_edtText = (EditText)findViewById(R.id.auth_input); 
        
        setResult(Activity.RESULT_CANCELED);
    }
}
